<?php
$oldchmod = substr($_GET['chmod'], 1);
?>
<script type="text/javascript"> 
function Oct(r,w,x) 
{
	i=0;
	if (r) { i+=4 };
	if (w) { i+=2 };
	if (x) { i+=1 };
	return i;
}
 
function Rechte()
{
	document.chmodform.newchmod.value=""+
	  Oct(document.chmodform.or.checked, document.chmodform.ow.checked, document.chmodform.ox.checked)+
	  Oct(document.chmodform.gr.checked, document.chmodform.gw.checked, document.chmodform.gx.checked)+
	  Oct(document.chmodform.ar.checked, document.chmodform.aw.checked, document.chmodform.ax.checked);
}

function chmodcheckbox()
{
	var chmodvalue = document.chmodform.newchmod.value;
	
	var ownerbin = parseInt(chmodvalue.charAt(0)).toString(2);
	var groupbin = parseInt(chmodvalue.charAt(1)).toString(2);
	var otherbin = parseInt(chmodvalue.charAt(2)).toString(2);

	while(ownerbin.length<3)
		ownerbin="0"+ownerbin; 
	while(groupbin.length<3)
		groupbin="0"+groupbin;
	while(otherbin.length<3)
		otherbin="0"+otherbin;

	document.chmodform.or.checked = parseInt(ownerbin.charAt(0)); 
	document.chmodform.gr.checked = parseInt(groupbin.charAt(0));
	document.chmodform.ar.checked = parseInt(otherbin.charAt(0));
	document.chmodform.ow.checked = parseInt(ownerbin.charAt(1)); 
	document.chmodform.gw.checked = parseInt(groupbin.charAt(1));
	document.chmodform.aw.checked = parseInt(otherbin.charAt(1));
	document.chmodform.ox.checked = parseInt(ownerbin.charAt(2)); 
	document.chmodform.gx.checked = parseInt(groupbin.charAt(2));
	document.chmodform.ax.checked = parseInt(otherbin.charAt(2));
}
</script> 

<form name="chmodform">
	<div style="text-align: center; padding: 15px 20px">
		<table align="center" cellspacing="4"> 
			<tr> 
				<td align="left" width="33%">
					<b>Besitzer</b>
				</td> 
				<td align="left" width="33%">
					<b>Gruppe</b>
				</td> 
				<td align="left" width="34%">
					<b>Jeder</b>
				</td> 
			</tr> 
	
			<tr> 
				<td align="left">
					<input type="checkbox" checked="checked" name="or" id="or" onclick="Rechte()" /> 
					<label for="or"> Lesen</label>
				</td> 
				<td align="left">
					<input type="checkbox" checked="checked" name="gr" id="gr" onclick="Rechte()" />
					<label for="gr"> Lesen</label>
				</td>
				<td align="left">
					<input type="checkbox" checked="checked" name="ar" id="ar" onclick="Rechte()" />
					<label for="ar"> Lesen</label>
				</td> 
			</tr> 
			
			<tr> 
				<td align="left">
					<input type="checkbox" checked="checked" name="ow" id="ow" onclick="Rechte()" /> 
					<label for="ow"> Schreiben</label>
				</td> 
				<td align="left">
					<input type="checkbox" checked="checked" name="gw" id="gw" onclick="Rechte()" />
					<label for="gw"> Schreiben</label>
				</td>
				<td align="left">
					<input type="checkbox" checked="checked" name="aw" id="aw" onclick="Rechte()" />
					<label for="aw"> Schreiben</label>
				</td> 
			</tr> 
			
			<tr> 
				<td align="left">
					<input type="checkbox" checked="checked" name="ox" id="ox" onclick="Rechte()" /> 
					<label for="ox"> Ausführen</label>
				</td> 
				<td align="left">
					<input type="checkbox" checked="checked" name="gx" id="gx" onclick="Rechte()" />
					<label for="gx"> Ausführen</label>
				</td>
				<td align="left">
					<input type="checkbox" checked="checked" name="ax" id="ax" onclick="Rechte()" />
					<label for="ax"> Ausführen</label>
				</td> 
			</tr> 
			
			<tr>
				<td colspan="3">
					<input 
						type="text" 
						name="newchmod" 
						value="<?php echo $oldchmod; ?>" 
						onkeyup="chmodcheckbox()" 
						size="2" />
					<input 
						type="button" 
						value="Berechtigung ändern"
						onclick='ajaxfade("ajax/showdirectory.php?chmod="+document.chmodform.newchmod.value+"&tochmod=<?php echo $_GET['tochmod']; ?>&dir=<?php echo $_GET['dir']; ?>", "#slider");' />
				</td>
			</tr>
		</table>
	</div>
</form>